package com.zklh.leetcode.greedy.easy.problem121;

import java.util.Arrays;
import java.util.Collections;

/**
 * @descrpiton 股票问题1 使用贪心算法思想实现
 * @author 坐看落花
 * @version 1.0
 * @date 2020/6/1
 */
public class Solution {
    public int maxProfit(int[] prices) {
        int mixPrice = Integer.MAX_VALUE, maxProfit = 0;
        for (int i = 0; i < prices.length; i++) {
            if (prices[i] < mixPrice) {
                mixPrice = prices[i];
            }
            if (prices[i] - mixPrice > maxProfit) {
                maxProfit = prices[i] - mixPrice;
            }
        }
        return maxProfit;
    }


    public static void main(String[] args){
        Solution solution = new Solution();
        System.out.println(solution.maxProfit(new int[]{7,6,4,3,1}));
    }
}

